﻿using HML.Design;
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;

namespace HML
{
    /// <summary>
    /// SingleAccordion滚动条
    /// </summary>
    [TypeConverter(typeof(PropertyOrderConverter))]
    public class SingleAccordionScrollStyle
    {
        #region 属性

        private bool autoHide = false;
        /// <summary>
        ///是否自动隐藏
        /// </summary>
        [Description("是否自动隐藏")]
        [Category("杂项")]
        [PropertyOrder(-200)]
        [DefaultValue(false)]
        public bool AutoHide
        {
            get { return this.autoHide; }
            set
            {
                if (this.autoHide == value)
                    return;

                this.autoHide = value;
                this.Invalidate();
            }
        }

        private int barThickness = 10;
        /// <summary>
        /// 滚动条厚度
        /// </summary>
        [Description("滚动条厚度")]
        [Category("杂项")]
        [PropertyOrder(-198)]
        [DefaultValue(10)]
        public int BarThickness
        {
            get { return this.barThickness; }
            set
            {
                if (this.barThickness == value || value < 0)
                    return;

                this.barThickness = value;
                this.owner.UpdateScrollRectangle();
                this.Invalidate();
            }
        }

        private Color barColor = Color.FromArgb(60, 64, 64, 64);
        /// <summary>
        /// 滑条背景颜色
        /// </summary>
        [Description("滑条背景颜色")]
        [Category("杂项")]
        [PropertyOrder(-194)]
        [DefaultValue(typeof(Color), "60, 64, 64, 64")]
        [Editor(typeof(AlphaColorEditor), typeof(UITypeEditor))]
        public Color BarColor
        {
            get { return this.barColor; }
            set
            {
                if (this.barColor == value)
                    return;

                this.barColor = value;
                this.Invalidate();
            }
        }

        private int slideMinSize = 26;
        /// <summary>
        /// 滑块最小Size
        /// </summary>
        [Description("滑块最小Size")]
        [Category("杂项")]
        [PropertyOrder(-192)]
        [DefaultValue(26)]
        public int SlideMinSize
        {
            get { return this.slideMinSize; }
            set
            {
                if (this.slideMinSize == value || value < 1)
                    return;

                this.slideMinSize = value;
                this.Invalidate();
            }
        }

        private bool slideRoundEnabled = false;
        /// <summary>
        /// 滑块是否为圆角
        /// </summary>
        [Description("滑块是否为圆角")]
        [Category("杂项")]
        [PropertyOrder(-191)]
        [DefaultValue(false)]
        public bool SlideRoundEnabled
        {
            get { return this.slideRoundEnabled; }
            set
            {
                if (this.slideRoundEnabled == value)
                    return;

                this.slideRoundEnabled = value;
                this.Invalidate();
            }
        }

        private Color slideNormalColor = Color.FromArgb(100, 64, 64, 64);
        /// <summary>
        /// 滑块颜色（正常）
        /// </summary>
        [Description("滑块颜色（正常）")]
        [Category("杂项")]
        [PropertyOrder(-190)]
        [DefaultValue(typeof(Color), "100, 64, 64, 64")]
        [Editor(typeof(AlphaColorEditor), typeof(UITypeEditor))]
        public Color SlideNormalColor
        {
            get { return this.slideNormalColor; }
            set
            {
                if (this.slideNormalColor == value)
                    return;

                this.slideNormalColor = value;
                this.Invalidate();
            }
        }

        private Color slideEnterColor = Color.FromArgb(160, 64, 64, 64);
        /// <summary>
        /// 滑块颜色（鼠标进入）
        /// </summary>
        [Description("滑块颜色（鼠标进入）")]
        [Category("杂项")]
        [PropertyOrder(-188)]
        [DefaultValue(typeof(Color), "160,64, 64, 64")]
        [Editor(typeof(AlphaColorEditor), typeof(UITypeEditor))]
        public Color SlideEnterColor
        {
            get { return this.slideEnterColor; }
            set
            {
                if (this.slideEnterColor == value)
                    return;

                this.slideEnterColor = value;
                this.Invalidate();
            }
        }

        /// <summary>
        /// 滑条Rect
        /// </summary>
        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public Rectangle BarRect { get; set; }

        /// <summary>
        /// 滑块rect
        /// </summary>
        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public Rectangle SlideRect { get; set; }

        #endregion

        #region 字段

        private SingleAccordion owner = null;

        #endregion

        public SingleAccordionScrollStyle(SingleAccordion owner)
        {
            this.owner = owner;
        }

        #region 私有方法

        /// <summary>
        /// 刷新控件
        /// </summary>
        private void Invalidate()
        {
            if (this.owner != null)
            {
                this.owner.Invalidate();
            }
        }

        #endregion
    }
}
